<%@ page import="com.pyrsana.faith.membership.Profile" %>
<r:require modules="form" />

<g:set var="namePrefix" value="${userInstance ? 'profile.' : '' }" />

<fieldset class="fields">
	<legend>Profile</legend>
	<div class="fieldcontain ${hasErrors(bean: profileInstance, field: 'first', 'error')} required">
		<label for="${namePrefix}first">
			<g:message code="${namePrefix}first.label" default="First Name" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}first" required="" maxlength="15" value="${profileInstance?.first}" />
	</div>
	
	<div class="fieldcontain ${hasErrors(bean: profileInstance, field: 'middle', 'error')}">
		<label for="${namePrefix}middle">
			<g:message code="${namePrefix}middle.label" default="Middle" />
		</label>
		<g:textField name="${namePrefix}middle" maxlength="15" value="${profileInstance?.middle}" />
	</div>
	
	<div class="fieldcontain ${hasErrors(bean: profileInstance, field: 'last', 'error')} required">
		<label for="${namePrefix}last">
			<g:message code="${namePrefix}last.label" default="Last Name" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}last" required="" maxlength="15" value="${profileInstance?.last}" />
	</div>
	
	<div class="fieldcontain ${hasErrors(bean: profileInstance, field: 'birthday', 'error')} required">
		<label for="${namePrefix}birthday">
			<g:message code="${namePrefix}birthday.label" default="Birthday" /><span class="required-indicator">*</span>
		</label>
		<g:datePicker name="${namePrefix}birthday" precision="day" value="${profileInstance?.birthday}" />
	</div>
	
	<div class="fieldcontain ${hasErrors(bean: profileInstance, field: 'gender', 'error')} required">
		<label for="${namePrefix}gender">
			<g:message code="${namePrefix}gender.label" default="Gender" /><span class="required-indicator">*</span>
		</label>
		<input type="radio" name="${namePrefix}gender" required="" value="M" ${"M".equals(profileInstance?.gender) ? "checked" : ""}>&nbsp;Male&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="radio" name="${namePrefix}gender" required="" value="F" ${"F".equals(profileInstance?.gender) ? "checked" : ""}>&nbsp;Female
	</div>
</fieldset>

<fieldset class="fields">
	<legend>Contact</legend>
	
	<g:set var="emailAddress" value="${profileInstance?.emailAddresses?.iterator()?.next()}" />
	<div class="fieldcontain ${hasErrors(bean: emailAddress, field: 'address', 'error')} required">
		<label for="${namePrefix}emailAddresses[0].address">
			<g:message code="${namePrefix}emailAddresses.label" default="Email Address" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}emailAddresses[0].address" required="" maxlength="50" value="${emailAddress?.address}" />
	</div>
	
	<g:set var="phoneNumber" value="${profileInstance?.phoneNumbers?.iterator()?.next()}" />
	<div class="fieldcontain ${hasErrors(bean: phoneNumber, field: 'number', 'error')} required">
		<label for="${namePrefix}phoneNumbers[0].number">
			<g:message code="${namePrefix}phoneNumbers.label" default="Phone Number" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}phoneNumbers[0].number" required="" maxlength="15" value="${phoneNumber?.number}" />
	</div>
	
	<g:set var="address" value="${profileInstance?.addresses?.iterator()?.next()}" />
	<div class="fieldcontain ${hasErrors(bean: address, field: 'streetAddress', 'error')} required">
		<label for="${namePrefix}addresses[0].streetAddress">
			<g:message code="${namePrefix}addresses.streetAddress.label" default="Street Address" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}addresses[0].streetAddress" required="" maxlength="50" value="${address?.streetAddress}" />
	</div>
	<div class="fieldcontain ${hasErrors(bean: address, field: 'city', 'error')} required">
		<label for="${namePrefix}addresses[0].city">
			<g:message code="${namePrefix}addresses.city.label" default="City" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}addresses[0].city" required="" maxlength="15" value="${address?.city}" />
	</div>
	<div class="fieldcontain ${hasErrors(bean: address, field: 'state', 'error')} required">
		<label for="${namePrefix}addresses[0].state">
			<g:message code="${namePrefix}addresses[0].state.label" default="State" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}addresses[0].state" required="" maxlength="2" value="${address?.state}" />
	</div>
	<div class="fieldcontain ${hasErrors(bean: address, field: 'zipcode', 'error')} required">
		<label for="${namePrefix}addresses[0].zipcode">
			<g:message code="${namePrefix}addresses.zipcode.label" default="Zipcode" /><span class="required-indicator">*</span>
		</label>
		<g:textField name="${namePrefix}addresses[0].zipcode" required="" maxlength="5" value="${address?.zipcode}" />
	</div>
</fieldset>